package engine.logic.login
{
	import engine.data.ModelLocator;
	import engine.logic.tips.TipsManage;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.text.TextField;
	import flash.ui.Keyboard;
	
	import newx.com.config.StaticIni;
	import newx.com.loader.SwfLoader;
	import newx.utils.debug.IO;

	public class RoleCreateGroup2 implements ILoginUI
	{
		private var _contentMC:MovieClip;
		private var _container:MovieClip;
		
		//interactive btns,初始化时赋值
		private var _startBtn			:SimpleButton;
		private var _randomNameBtn		:SimpleButton;
		private var _role_0			:MovieClip;
		private var _role_1			:MovieClip;
		private var _role_2			:MovieClip;
		private var _role_3			:MovieClip;
		private var _role_4			:MovieClip;
		
		private var _roleModel			:MovieClip;
//		private var _nameMc			:MovieClip;
		private var _nameInput			:TextField;
//		private var _back				:MovieClip
		//选择的角色
		private var _clickChooseMC		:MovieClip;
		/**
		 *玩家形象 0：唐门女 1：唐门男 2：少林 3：武当女 4：武当男 
		 */		
		private var _roleAvter:int;

		//data
		private var _roleCastleId:int  =	0;
		private var _roleRaceId:int	=	0;
		private var _roleOccupationId:int;
		private var _roleName:String;
		private var _roleSexId:int;
		
		private var _firstNameBoyArr:Array;
		private var _firstNameGirlArr:Array;
		private var _secondNameArr:Array;
		private var _randomedName:Object = {};
		
		private var _raceOccupation:Array;
		private var _occupationNums:uint=7;
		private var _raceNums:uint = 4;
		
		
		private var _completeCallBack:Function;
		//滑过的头像
		private var overObj:MovieClip;
		/**
		 *3选择状态 2 滑过状态   1未选中 
		 */		
		private const SELECTED_STATE:int =3,
						OVER_STATE:int=2,
						NO_SELECTED:int =1;
		//tool box
		private var _blurTX:BlurTX = new BlurTX();
		
		private var _lastRoleURL:String = "";
		
		public function RoleCreateGroup2(mc:MovieClip,_loginContainer:MovieClip)
		{
			
			_contentMC = mc.roleCreateUI;
			_contentMC.x = 100;
			_contentMC.y = 0;
			
			_container = _loginContainer;
			
			//初始化显示资源
			_randomNameBtn	=	_contentMC.bt_1;
			_startBtn		=	_contentMC.enterBtn;
			_role_0			=	_contentMC.mc_00;
			_role_1			=	_contentMC.mc_01;
			_role_2			=	_contentMC.mc_02;
			_role_3			=	_contentMC.mc_03;
			_role_4			=	_contentMC.mc_04;
			_nameInput		=	_contentMC.Name;
			_roleModel		=   _contentMC.model;
			_role_0.gotoAndStop(NO_SELECTED);
			_role_1.gotoAndStop(NO_SELECTED);
			_role_2.gotoAndStop(NO_SELECTED);
			_role_3.gotoAndStop(NO_SELECTED);
			_role_4.gotoAndStop(NO_SELECTED);
			
			_role_0.mouseChildren	=	_role_1.mouseChildren	=	_role_2.mouseChildren = _role_3.mouseChildren = _role_4.mouseChildren	=	true;
			_role_0.buttonMode	=	_role_1.buttonMode	=	_role_2.buttonMode = _role_3.buttonMode = _role_4.buttonMode	=	true;
		

			getRandomAvter();
			_nameInput.text = getRandomName(); //随机姓名

			addListener()
//			_occuBg		=	_contentMC.occupationIconBg;
//			_rolePicContainer	=	_contentMC.face_mc;
//			_nameInput	=	_contentMC.nameInput;
//			_nameRandomBtn	=	_contentMC.nameSj;
//			_nameRandomBtn.buttonMode = true;
//			
//			_manRadio = _contentMC.nan_1;
//			_manRadio.buttonMode = true;
//			_womanRadio = _contentMC.nv_2;
//			_womanRadio.buttonMode = true;
//			
//			_zyDescribeTxt = _contentMC.zy_txt;
//			
//			_occuSelectedMc = _contentMC.custSkinxg;
			//End
			
			//种族可选职业列表
//			_raceOccupation=[];
//			_raceNums = int(StaticIni.getIniVar("GameRaceConfig","raceNums"));
//			var rNameObj:Object = StaticIni.getIniObj("RandomName");
//			_firstNameBoyArr = StaticIni.getSwfLangStr(String(rNameObj.firstNameBoy)).split(",");
//			_firstNameGirlArr =  StaticIni.getSwfLangStr(String(rNameObj.firstNameGirl)).split(",");
//			_secondNameArr = StaticIni.getSwfLangStr(String(rNameObj.secondName)).split(",");
//			var i:uint = 0;
//			for(i=0;	i<_raceNums;	i++)
//			{
//				_raceOccupation.push(StaticIni.getIniVar("GameRaceConfig","race"+i+"_zyinfo"));
//				
//				getRaceBtn(i).addEventListener(MouseEvent.MOUSE_DOWN,raceBtnMouseDownHandler);
//				getRaceBtn(i).addEventListener(MouseEvent.ROLL_OVER,raceBtnMouseOverHandler);
//				getRaceBtn(i).addEventListener(MouseEvent.ROLL_OUT,raceBtnMouseOutHandler);
//			}
//			
//			for(i=0; i<_occupationNums; i++)
//			{
//				getOccupationBtn(i).addEventListener(MouseEvent.MOUSE_DOWN,occuBtnMouseDownHandler);
//			}
//			
////			_nameInput.addEventListener(TextEvent.TEXT_INPUT,roleNameInputHandler);
////			_nameInput.addEventListener(KeyboardEvent.KEY_DOWN,keyEnterHandler);
////			_nameRandomBtn.addEventListener(MouseEvent.MOUSE_DOWN,nameRandomBtnMouseDownHandler);
////			
////			_startBtn.addEventListener(MouseEvent.MOUSE_DOWN,startMouseDownHandler);
////			_startBtn.addEventListener(MouseEvent.MOUSE_UP,startMouseUpHandler);
////			
////			_manRadio.addEventListener(MouseEvent.MOUSE_DOWN,manRadioMouseDownHandler);
////			_womanRadio.addEventListener(MouseEvent.MOUSE_DOWN,womanMouseDownHandler);
//			
//			

//			
//			//初始化默认选择项,随机
//			_roleRaceId = Math.floor( 4*Math.random() );
//			resetRaceIcons();
//			
//			//确定需要显示的职业
//			resetOccuIconById(_roleRaceId);
//
//			//选中该职业 ,根据当前的种族，随机一个
//			_roleOccupationId = getRandomOccu(_roleRaceId);
//			resetOccupationIcon();
//			
//			resetOccuTextIcon();
//			
//			_roleCastleId = 10; //随机城堡
//			
//			_roleSexId = Math.floor( 2*Math.random() );  //随机性别
//			resetSexRadioBtn();
//			_nameInput.text = getRandomName(); //随机姓名
//			
//			resetDiscribeTxt();
//			resetRolePic();
			
//			_contentMC.addChildAt(_back,0);
			//开始加载地图
			//SwfLoader.StartLoad("res/swf/RoleCreateBG.swf",null,bgCompleteHandler);
			
		}
		private function addListener():void
		{
			
			_nameInput.		addEventListener(Event.CHANGE,		roleNameInputHandler);
			_nameInput.		addEventListener(KeyboardEvent.KEY_DOWN,	keyEnterHandler);
			_randomNameBtn.	addEventListener(MouseEvent.MOUSE_DOWN,		nameRandomBtnMouseDownHandler);
			_startBtn.		addEventListener(MouseEvent.MOUSE_DOWN,		startMouseDownHandler);
			addItemEvent(_role_0);
			addItemEvent(_role_1);
			addItemEvent(_role_2);
			addItemEvent(_role_3);
			addItemEvent(_role_4);
		}
		private function removeListener():void
		{
			_nameInput.		removeEventListener(Event.CHANGE,		roleNameInputHandler);
			_nameInput.		removeEventListener(KeyboardEvent.KEY_DOWN,		keyEnterHandler);
			_randomNameBtn.	removeEventListener(MouseEvent.MOUSE_DOWN,		nameRandomBtnMouseDownHandler);
			_startBtn.		removeEventListener(MouseEvent.MOUSE_DOWN,		startMouseDownHandler);
			removeItemEvent(_role_0);
			removeItemEvent(_role_1);
			removeItemEvent(_role_2);
			removeItemEvent(_role_3);
			removeItemEvent(_role_4);
		}
		/**
		 * 添加对像事件 
		 * @param val
		 * 
		 */		
		private function addItemEvent(val:DisplayObject):void
		{
			val.addEventListener(MouseEvent.CLICK, 		mouseClickHandle);
			val.addEventListener(MouseEvent.MOUSE_OVER, mouseOvetHandle);
			val.addEventListener(MouseEvent.MOUSE_OUT, 	mouseOutHandle);
		}
		/**
		 * 删除对像事件 
		 * @param val
		 * 
		 */		
		private function removeItemEvent(val:DisplayObject):void
		{
			val.removeEventListener(MouseEvent.CLICK,		mouseClickHandle);
			val.removeEventListener(MouseEvent.MOUSE_OVER, 	mouseOvetHandle);
			val.removeEventListener(MouseEvent.MOUSE_OUT, 	mouseOutHandle);
		}
		/**
		 * 选角色 
		 * @param e
		 * 
		 */		
		private function mouseClickHandle(e:MouseEvent):void
		{
			var itemMC:MovieClip	=	(e.currentTarget as MovieClip) 
			var roleIndex:int;
			var tempSex:int	;
			if(itemMC != _clickChooseMC)
			{
				if(_clickChooseMC != null)
				{
					_clickChooseMC.gotoAndStop(NO_SELECTED);
//					if(_clickChooseMC.hasEventListener(Event.ENTER_FRAME))
//					{
//						_clickChooseMC.removeEventListener(Event.ENTER_FRAME,nextFrameHandle);
//						_clickChooseMC.removeEventListener(Event.ENTER_FRAME,preFrameHandle);
//					}
//					_clickChooseMC.addEventListener(Event.ENTER_FRAME,preFrameHandle);
				}
				
//				if(itemMC.hasEventListener(Event.ENTER_FRAME))
//				{
//					itemMC.removeEventListener(Event.ENTER_FRAME,nextFrameHandle);
//					itemMC.removeEventListener(Event.ENTER_FRAME,preFrameHandle);
//				}
//				itemMC.addEventListener(Event.ENTER_FRAME,nextFrameHandle);
				itemMC.gotoAndStop(SELECTED_STATE);
				_roleAvter	=	int(itemMC.name.slice((itemMC.name as String).length - 1,(itemMC.name as String).length));
				_clickChooseMC	=	itemMC;
				_roleModel.gotoAndStop(_roleAvter+1)
				if(_roleAvter ==1|| _roleAvter == 2 || _roleAvter == 4)
				{
					tempSex	= 1;
				}
				else
				{
					tempSex	=	2;
				}
				if(tempSex != _roleSexId)
				{
					_roleSexId	=	tempSex;
					_nameInput.text = getRandomName()
				}
			}
		}
		/**
		 * 查看 
		 * @param e
		 * 
		 */		
		private function mouseOvetHandle(e:MouseEvent):void
		{
			var itemMC:MovieClip	=	(e.currentTarget as MovieClip);
			var roleIndex:int;
			if(overObj)
			{
				if(overObj!=_clickChooseMC)
				{
					overObj.gotoAndStop(NO_SELECTED);
				}
				else
					overObj.gotoAndStop(SELECTED_STATE);
			}
			itemMC.gotoAndStop(OVER_STATE);
			overObj =itemMC
//			if(itemMC != _clickChooseMC)
//			{
//				if(itemMC.hasEventListener(Event.ENTER_FRAME))
//				{
//					itemMC.removeEventListener(Event.ENTER_FRAME,nextFrameHandle);
//					itemMC.removeEventListener(Event.ENTER_FRAME,preFrameHandle);
//				}
//				itemMC.addEventListener(Event.ENTER_FRAME,nextFrameHandle);
//				//roleIndex	=	int(itemMC.name.slice((itemMC.name as String).length - 1,(itemMC.name as String).length));
////				_nameMc.gotoAndStop(roleIndex +1);
//			}
			
		}
		private function mouseOutHandle(e:MouseEvent):void
		{
			var itemMC:MovieClip	=	(e.currentTarget as MovieClip);
			if(itemMC != _clickChooseMC)
			{
				
				itemMC.gotoAndStop(NO_SELECTED);
//				if(itemMC.hasEventListener(Event.ENTER_FRAME))
//				{
//					itemMC.removeEventListener(Event.ENTER_FRAME,nextFrameHandle);
//					itemMC.removeEventListener(Event.ENTER_FRAME,preFrameHandle);
//				}
//				itemMC.addEventListener(Event.ENTER_FRAME,preFrameHandle);
			}
			if(overObj)
			{
				if(overObj!=_clickChooseMC)
				{
					overObj.gotoAndStop(NO_SELECTED);
				}
				else
					overObj.gotoAndStop(SELECTED_STATE);
			}
//			_nameMc.gotoAndStop(_roleAvter +1);
		}
		
		/**
		 * 随机姓名 
		 * @return 
		 * 
		 */	
		private function getRandomName():String
		{
			return getFirstName() + getSecondName();;
		}
		
		private function getFirstName():String
		{
			var firstNameLen 	: int = 772;
			
			var firstName : String = "";
			
			firstName = StaticIni.getSwfLangStr( "firstname_" + int( Math.random() * firstNameLen ) );
			
			if( firstName.indexOf( "firstname" ) != -1 || firstName == "")
			{
				return getFirstName();
			}else
			{
				return firstName;
			}
		}
		
		private function getSecondName():String
		{
			var boyNameLen 		: int = 280;
			var girlNameLen 	: int = 223;
			var secondName 		: String	= "";
			if(_roleSexId == 1)
			{
				secondName =  StaticIni.getSwfLangStr( "secondname_boy_" + int( Math.random() * boyNameLen ) )
			}else
			{
				secondName =  StaticIni.getSwfLangStr( "secondname_girl_" + int( Math.random() * girlNameLen ) );
			}
			
			if( secondName.indexOf( "secondname" ) != -1 || secondName == "" )
			{
				return getSecondName();
			}else
			{
				return secondName;
			}
		}

		
//		private function getRandomName():String
//		{
//			var firstNameSheet:Array;
//			var secondNameSheet:Array = _secondNameArr;
//			
//			firstNameSheet = (0 == _roleSexId) ? _firstNameBoyArr : _firstNameGirlArr;
//			
//			var firstIndex:int = firstNameSheet.length*Math.random();
//			var seconIndex:int = secondNameSheet.length*Math.random();
//			var firstName:String = firstNameSheet[firstIndex];
//			var secondName:String = secondNameSheet[seconIndex];
//			
//			var randomName:String = firstName+"·"+secondName;
//			
//			//如果已经随过100个，不防重复了，怕名字都是重复的，死循环
//			if(!_randomedName.hasOwnProperty("nameCount"))
//				_randomedName.nameCount = 0;
//			
//			while(_randomedName.hasOwnProperty(randomName))
//			{
//				firstIndex= Math.floor( firstNameSheet.length*Math.random() );
//				seconIndex = Math.floor( secondNameSheet.length*Math.random() );
//				
//				firstName = firstNameSheet[firstIndex];
//				secondName= secondNameSheet[seconIndex];
//				
//				//如果已经随过100个，不防重复了，怕名字都是重复的，死循环
//				if(_randomedName.nameCount > 100)
//					break;
//				
//				randomName = firstName + secondName;
//			}
//			
//			_randomedName.nameCount ++;
//			_randomedName[randomName] = true;
//			
//			return randomName;
//		}
		/**
		 * 随机角色：
		 */		
		private function getRandomAvter():void
		{
			if(_clickChooseMC != null)
			{
				_clickChooseMC.gotoAndStop(1);
			}
			_roleAvter	=	Math.round((Math.random()*(4-0)+0));	
			_clickChooseMC	=	this["_role_" + _roleAvter];
			_clickChooseMC.gotoAndStop(SELECTED_STATE)
			_roleModel.gotoAndStop(_roleAvter+1);
			if(_roleAvter == 1|| _roleAvter == 2 || _roleAvter == 4)
			{
				_roleSexId	= 1;  //男
			}
			else
			{
				_roleSexId	=	2; //女
			}
		}
		/**
		 * 回车 
		 * @param e
		 * 
		 */		
		private function keyEnterHandler(e:KeyboardEvent):void
		{
			if(	e.keyCode	==	Keyboard.ENTER	)
			{
				startMouseDownHandler(null);
			}
		}
		/**
		 * 开始游戏   1少林 2武当 3唐门
		 * @param e
		 * 
		 */		
		private function startMouseDownHandler(e:MouseEvent):void
		{
			_roleName 		=	_nameInput.text;
			
			_roleCastleId	=	_roleAvter
			_roleRaceId		=	_roleAvter
				
			if(_roleAvter == 0)
			{
				_roleRaceId	=	2
			}
			else if(_roleAvter == 1)
			{
				_roleRaceId	=	2
			}
			else if(_roleAvter == 2)
			{
				_roleRaceId	=	1
			}
			else if(_roleAvter == 3)
			{
				_roleRaceId	=	3
			}
			else if(_roleAvter == 4)
			{
				_roleRaceId	=	3
			}
			_roleOccupationId	=	_roleRaceId
			if(	null	!=	_completeCallBack)
			{
				var groupfbInfo:Object={
					castleId:_roleCastleId,
					raceId	:_roleRaceId,  //种族  
					occuId	:_roleOccupationId, //职业
					roleName:_roleName,   //名字
					sexId	:_roleSexId		//性别
				};
				
				_completeCallBack(groupfbInfo);
			}
		}
		/**
		 * 随机名称按钮 
		 * @param e
		 * 
		 */		
		private function nameRandomBtnMouseDownHandler(e:MouseEvent):void
		{
			_nameInput.text = getRandomName();
		}
		
		
		
		/**输入角色名检察，超过最大个数时提示错误问题*/
		private function roleNameInputHandler(e:Event):void
		{
			var tipMsg:Object;
			var txt:TextField		=	e.target as TextField;
			var enterName:String	=	txt.text;
			var firstW:String		=	enterName.charAt(0);
			
			if(isIllegalLetter(firstW))
			{
				e.preventDefault();	
				tipMsg				=	this.getRoleNameTipMsg();
				LoginAlert.showAlert(tipMsg.fError);
				txt.stage.focus	=	null;
				txt.text = getRandomName();
				return;
			}
			
			//长度限制
			var len:int				=	enterName.length;
			
			var maxStrNum:int		=	this.getRoleMaxNum();
			
			if(len>maxStrNum)
			{
				e.preventDefault();	
				tipMsg				=this.getRoleNameTipMsg();
				LoginAlert.showAlert(tipMsg.maxError);
				txt.stage.focus	=	null;
				txt.text 		= getRandomName();
			}
		}
		/**
		 * 读取名字最大长度 
		 * @return 
		 * 
		 */		
		private function getRoleMaxNum():int
		{
			return 	int(	StaticIni.getIniVar("GameroleNameRestrict","maxNum"));
		}
		private function bgCompleteHandler(val:DisplayObject,pList:Array):void
		{
			_contentMC.addChildAt(val,0);
		}
		/**
		 * 显示 
		 * @param info
		 * 
		 */		
		public function show(info:Object=null):void
		{
			_container.addChild(_contentMC);
		}
		
		public function recycle():void
		{
		}
		
		public function hide():void
		{
			if(_contentMC.parent)
				_contentMC.parent.removeChild(_contentMC);
		}
		
		public function set completeCallBack(cb:Function):void
		{
			_completeCallBack = cb;
		}
		

		private function startMouseUpHandler(e:MouseEvent):void
		{
			MovieClip(e.target).gotoAndStop(1);
		}
		
		private function manRadioMouseDownHandler(e:MouseEvent):void
		{
			if(_roleSexId == 0) return;
			
			_roleSexId = 0;
			resetSexRadioBtn();
//			resetRolePic();
			_nameInput.text = getRandomName();
		}
		
		private function womanMouseDownHandler(e:MouseEvent):void
		{
			if(_roleSexId == 1) return;
			
			_roleSexId = 1;
			resetSexRadioBtn();
//			resetRolePic();
			resetDiscribeTxt();
			
			_nameInput.text = getRandomName();
		}
		
		private function raceBtnMouseDownHandler(e:MouseEvent):void
		{
			if(false 	==	MovieClip(e.currentTarget).buttonMode)	return;
			
			var iconName:String=MovieClip(e.currentTarget).name;
			
			_roleRaceId	= int(	iconName.replace("zz_",""));
			
			
			resetRaceIcons();
			
			resetOccuIconById(_roleRaceId);
			//种族切换时默认选职业0
			_roleOccupationId = getRandomOccu(_roleRaceId);
			
			resetOccuTextIcon();
			
			resetOccupationIcon();
			resetDiscribeTxt();
//			resetRolePic();
		}
		private function raceBtnMouseOverHandler(e:MouseEvent):void
		{
			var iconName:String=MovieClip(e.currentTarget).name;
			var raceId:int = int(	iconName.replace("zz_",""));
			TipsManage.showTips(StaticIni.getSwfLangStr(StaticIni.getIniVar("GameLoginConfig","zzinfo"+raceId)));
		}
		private function raceBtnMouseOutHandler(e:MouseEvent):void
		{
			TipsManage.hideTips();
		}
		
		
		private function occuBtnMouseDownHandler(e:MouseEvent):void
		{
			if(false 	==	MovieClip(e.currentTarget).buttonMode)	return;
			
			var iconName:String=MovieClip(e.currentTarget).name;
			
			_roleOccupationId	= int(	iconName.replace("zy_",""));
			
			resetOccuTextIcon();
			
			resetOccupationIcon();
//			resetRolePic();
			resetDiscribeTxt();
		}
		

		
		private function getRoleNameTipMsg():Object
		{
			//			AlertUI.showAlert(StaticIni.getSwfLangStr("UIStr_1000007"),StaticIni.getSwfLangStrVar("UIStr_1000831",[maxStrNum]),AlertUI.OK);
			
			var maxStrNum:int=getRoleMaxNum();
			var obj:Object=new Object();
			obj.title=StaticIni.getSwfLangStr("UIStr_1000007");
			obj.content= "UIStr_1000831"//StaticIni.getSwfLangStrVar("UIStr_1000831",[maxStrNum]);
			
			obj.maxError	=	"UIStr_1000967"//StaticIni.getSwfLangStrVar("UIStr_1000967",[maxStrNum]);
			
			obj.fError		=	"UIStr_1000831"//StaticIni.getSwfLangStr("UIStr_1000831");
			return obj;
		}


		
		private function resLoadCompleteHandler(val:DisplayObject,pList:Array):void
		{	
			//如果加载的图片不是当前的图片，不处理
			if(_roleRaceId != pList[1]
			 || _roleOccupationId != pList[2]
			|| _roleSexId != pList[3])
				return;
			
//			if(val != null)
//			{
//				while(_rolePicContainer.numChildren>0)
//					_rolePicContainer.removeChildAt(0);
//				
//				_rolePicContainer.addChild(val);
//				_blurTX.addOn(val);
//			}
//		}
//		
//		private function resetRolePic():void
//		{
//			if(_rolePicContainer.numChildren>0)
//			{
//				var mc:DisplayObject = _rolePicContainer.getChildAt(0);
//				_blurTX.removeOut(mc);
//			}
			
			SwfLoader.Close(_lastRoleURL);
			
			var picUrl:String = getRoleModelUrl(_roleRaceId,_roleOccupationId,_roleSexId);
			IO.traceLog("加载角色资源:"+picUrl);
			//出现进度条，锁定客户端。
			SwfLoader.StartLoad(picUrl,null,resLoadCompleteHandler,
				[null,_roleRaceId,_roleOccupationId,_roleSexId]);
			
			_lastRoleURL = picUrl;
		}
		
		private function resetOccuIconById(raceId:int):void
		{
			var occuList:Array	=	String(_raceOccupation[raceId]).split(",");
			
			var len:uint=occuList.length;
			var visibleOccuIcon:Array=[];
			var occuIcon:MovieClip;
//			var bg:MovieClip=_occuBg;
			
			for(var j:uint=0;	j<_occupationNums;		j++)
			{
				occuIcon=getOccupationBtn(j);
				occuIcon.gotoAndStop(2);
				occuIcon.visible=false;
				occuIcon.buttonMode=true;
			}
			
			for(var i:uint=0;	i<len;	i++)
			{
				occuIcon=getOccupationBtn(occuList[i]);	
				occuIcon.visible=true;
				visibleOccuIcon.push(occuIcon);
			}
			
//			this.averageArrange(visibleOccuIcon,bg);
		}
		
		private function resetOccupationIcon():void
		{
			var roleIcon:MovieClip;
			for(var i:uint=0;	i<_occupationNums;	i++)
			{
				roleIcon	=	getOccupationBtn(i);
//				roleIcon.gotoAndStop(2);
				roleIcon.buttonMode=true;
			}
			
//			getOccupationBtn(_roleOccupationId).gotoAndStop(1);
			roleIcon = getOccupationBtn(_roleOccupationId);
			roleIcon.buttonMode = false;
			
//			_occuSelectedMc.x = roleIcon.x - 13;
//			_occuSelectedMc.y = roleIcon.y - 13;
		}
		
		/***重设种族按钮*/
		private function resetRaceIcons():void
		{
			var raceIcon:MovieClip;
			var raceDiscribeIndex:String;
			var langStr:String;
			
			for(var i:uint=0;	i<_raceNums;	i++)
			{
				raceIcon = getRaceBtn(i);
				raceIcon.gotoAndStop(2);
				raceIcon.buttonMode=true;
			}
			
			getRaceBtn(_roleRaceId).gotoAndStop(1);
			getRaceBtn(_roleRaceId).buttonMode = false;
		}
		private function resetOccuTextIcon():void
		{
			var textIcon:MovieClip;
			
			for(var i:uint=0;	i<_occupationNums;	i++)
			{
				textIcon = getOccuTextIcon(i);
				textIcon.visible = false;
			}
			textIcon = getOccuTextIcon(_roleOccupationId);
			textIcon.visible = true;
//			textIcon.x = _zyDescribeTxt.x + (_zyDescribeTxt.width-textIcon.width)/2;
//			textIcon.y = _zyDescribeTxt.y -textIcon.height - 10;
		}
		
		/***重置性别按钮*/
		private function resetSexRadioBtn():void
		{
			if(0 == _roleSexId)
			{
//				_manRadio.gotoAndStop(1);
//				_womanRadio.gotoAndStop(2);
			}
			else
			{
//				_manRadio.gotoAndStop(2);
//				_womanRadio.gotoAndStop(1);
			}
		}
		/***重置职业描述文本*/
		private function resetDiscribeTxt():void
		{
//			_zyDescribeTxt.htmlText = StaticIni.getSwfLangStr("jobs_"+_roleOccupationId);
		}
		
		private function getRaceBtn(raceId:int):MovieClip
		{
			return _contentMC["zz_"+raceId];
		}
		private function getOccupationBtn(occuId:int):MovieClip
		{
			return _contentMC["zy_"+occuId];
		}
		private function getOccuTextIcon(occuId:int):MovieClip
		{
			return	_contentMC["zymz_"+occuId]; 
		}
		
		/**
		 * [真实地址,待机地址] 
		 */		
		private function getRoleModelUrl(raceId:int,occuId:int,sexId:int):String
		{
			var prefix:String=ModelLocator.getInstance().mainIni.getContent("loginConfig","login_res_path");
			var url:String=StaticIni.getIniVar("GameLoginConfig","zy"+raceId+"_"+occuId+"_"+sexId);
			return prefix+url;
		}
		
		private function getRandomOccu(raceId:int):int
		{
			var occuList:Array	=	String(_raceOccupation[raceId]).split(",");
			var randomIndex:int = Math.floor( occuList.length*Math.random() );
			return int(occuList[randomIndex]);
		}
		
		/**
		 * 将一组显示对象排列在指定的背景上,使用时保证所有显示对象在同一级
		 * @param targetList
		 * @param bg
		 * 
		 */		
		private function averageArrange(targetList:Array,bg:MovieClip):void
		{
			var len:uint=targetList.length;
			
			var gapX:Number;
			var totalWidth:Number=0;
			for(var i:uint=0;	i<len;	i++)
			{
				totalWidth+=	targetList[i].width;
			}
			gapX=(bg.width-totalWidth)/(len-1);
			
			var offsetX:Number=0;
			for(var j:uint=0;	j<len	;j++)
			{
				targetList[j].x=bg.x+offsetX;
				targetList[j].y=bg.y+(bg.height-targetList[j].height)/2;
				
				offsetX+=targetList[j].width+gapX;
			}
		}
		/**
		 * 是否是非法字符
		 * @param str
		 * @return 
		 */		
		private function isIllegalLetter(str:String):Boolean
		{
			var arr:Array=["_","0","1","2","3","4","5","6","7","8","9"];
			for(var i:int=0;i<11;i++)
			{
				if(str==arr[i])
				{
					return true;
				}
			}
			return false;
		}
		/**
		 * 正播
		 * @param e
		 * 
		 */		
		private function nextFrameHandle(e:Event):void
		{
			var item:MovieClip	=	(e.target as MovieClip) as MovieClip;
			if(item.currentFrame >= item.totalFrames)
			{
				(item.parent as MovieClip).removeEventListener(Event.EXIT_FRAME,nextFrameHandle);
			}
			else
			{
				item.gotoAndStop(item.currentFrame + 1);
			}
		}
		/**
		 * 回放 
		 * @param e
		 * 
		 */		
		private function preFrameHandle(e:Event):void
		{
			var item:MovieClip	=	(e.target as MovieClip) as MovieClip;
			if(item.currentFrame <= 0)
			{
				(item.parent as MovieClip).removeEventListener(Event.EXIT_FRAME,preFrameHandle);
			}
			else
			{
				item.gotoAndStop(item.currentFrame - 1);
			}
		}
	}
}